﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using DICE_GS;

public class MyUnitListManager : LTEventListenerC {
	public DeckEditSceneManager sceneManager;
	public List<MyUnitCard> cardList = new List<MyUnitCard>();
//	public MyUnitCard[] cardList = new MyUnitCard[MyInfo.Instance.MyUnitsList.Count];
    public MyUnitCard detailCard;
    public GameObject detailCardBlank;

    public GameObject skillInfoObject;
    public UILabel skillName;
    public UILabel skillDesc;
    public UILabel skillMP;
	
    Transform panelTrans;
	// Use this for initialization
	float cardWidth = 0;
    Vector3 scrollViewOriginalPosX;
	void Start () {
        panelTrans = NGUITools.FindInParents<UIPanel>(gameObject).transform;
		cardWidth = GetComponent<UIGrid>().cellWidth;
        scrollViewOriginalPosX = transform.parent.localPosition;
        Debug.LogError(transform.parent.GetComponent<UIPanel>().clipOffset);
//		LoadingWindow.window.ShowShortLoading();
//		int index = 0;
//		for(int i=0; i<MyInfo.Instance.MyUnitsList.Count; i++)
////		foreach(UnitInfo unitInfo in MyInfo.Instance.MyUnitsList)
//		{
//			MyUnitCard card = LTPrefabManager.InstantiateC(PrefabTypes.Card, Vector3.zero, Quaternion.identity) as MyUnitCard;
//			Transform cardTrans = card.transform;
//			cardTrans.parent = transform;
//			cardTrans.localScale = Vector3.one;
//			card.SetCardInfo(index, MyInfo.Instance.MyUnitsList[i]); 
//			card.GetComponent<UIButtonMessage>().target = card.gameObject;
//			card.GetComponent<LTButtonMessage>().m_MethodDeliver[0].m_EventListener = this;
//			card.GetComponent<LTButtonMessage>().m_MethodDeliver[0].m_EventId = index;
////			card.manager = sceneManager;
////			card.listManager = this;
//			card.index = index++;
//			card.disableOnPress = true;
//			
//			foreach(KeyValuePair<int, UnitInfo> pair in MyInfo.Instance.MyDeckMap[MyInfo.Instance.MyCurrentDeck].SlotMap)
//			{
//				if( pair.Value.UnitDBID == MyInfo.Instance.MyUnitsList[i].UnitDBID )
//				{
//					card.selectedMark.gameObject.SetActive(true);
//					card.collider.enabled = false;
//				}
//			}
//
//			
////			cardList.Add(card);
//		}
//		
//		GetComponent<UIGrid>().Reposition();
//		LoadingWindow.window.HideLoading();
		
        //return Co_SetupCardList();
//		StartCoroutine("Co_SetupCardList");
	}

    void OnEnable()
    {
        //if (cardList.Count != 0)
        //{
        //    foreach (MyUnitCard card in cardList)
        //    {
        //        LTButtonMessage msg = card.GetComponent<LTButtonMessage>();
        //        card.alreadySettingLabel.SetActive(false);
        //        msg.enabled = true;
        //        msg.m_MethodDeliver[0].m_EventListener = this;
        //        card.unitImage.alpha = 1f;
                
        //        for (int j = 0; j < MyInfo.Instance.MyDeckMap[MyInfo.Instance.MyCurrentDeck].SlotMap.Count; j++)
        //        {
        //            if (MyInfo.Instance.MyDeckMap[MyInfo.Instance.MyCurrentDeck].SlotMap[j].UnitDBID == card._unitInfo.UnitDBID)
        //            {
        //                card.alreadySettingLabel.SetActive(true);
        //                //card.equipInfoObject.SetActive(true);
        //                //card.equipInfoObject.GetComponentInChildren<UILabel>().text = CStringTableManager.Instance.GetItemById(1693).Replace("{index}", (j + 1).ToString());
        //                //					card.selectedMark.gameObject.SetActive(true);
        //                //					card.collider.enabled = false;
        //                msg.enabled = false;
        //                msg.m_MethodDeliver[0].m_EventListener = null;
        //                card.unitImage.alpha = 0.5f;
        //                break;
        //            }
        //        }

        //        if (MyInfo.Instance.MyDeckMap[MyInfo.Instance.MyCurrentDeck].GetSameCardCount(card._unitInfo.UnitClassID) >= 2)
        //        {
        //            //if (!card.equipInfoObject.activeSelf)
        //            //    card.equipLimitObject.SetActive(true);
        //            msg.enabled = false;
        //            msg.m_MethodDeliver[0].m_EventListener = null;
        //            card.unitImage.alpha = 0.5f;
        //        }
        //    }
        //}

        StartCoroutine("Co_SetupCardList");
		if(MyInfo.Instance.currentDeckInfo.SlotMap[DeckEditSceneManager.selectedDeckIndex].UnitDBID != 0)
		{
			SetDetailCardInfo(MyInfo.Instance.currentDeckInfo.SlotMap[DeckEditSceneManager.selectedDeckIndex]);
			SetSkillInfo(MyInfo.Instance.currentDeckInfo.SlotMap[DeckEditSceneManager.selectedDeckIndex].UnitClassID);
		}
    }

    int loadingPageIndex = 1;
    int currentLoadingCardIndex=0;
	IEnumerator Co_SetupCardList()
	{
		yield return null;
		LoadingWindow.window.ShowShortLoading();
        for (int i=0; i<(MyInfo.Instance.MyUnitsList.Count<7?MyInfo.Instance.MyUnitsList.Count:7); i++)
//		foreach(UnitInfo unitInfo in MyInfo.Instance.MyUnitsList)
		{
            MyUnitCard card;
            Debug.Log(CSceneManager.prevSceneIndex);
            if (CSceneManager.prevSceneIndex == SCENE.UnitMenuScene  || CSceneManager.prevSceneIndex == SCENE.UnitLevelupScene)
                card = LTPrefabManager.InstantiateC(PrefabTypes.Card, Vector3.zero, Quaternion.identity) as MyUnitCard;
            else
                card = LTPrefabManager.InstantiateC(PrefabTypes.Card1, Vector3.zero, Quaternion.identity) as MyUnitCard;
			Transform cardTrans = card.transform;
			cardTrans.parent = transform;
			cardTrans.localScale = new Vector3(0.8f, 0.8f, 1f);
			card.SetCardInfo(i, MyInfo.Instance.MyUnitsList[i]); 
			card.GetComponent<UIButtonMessage>().target = card.gameObject;
			LTButtonMessage msg = card.GetComponent<LTButtonMessage>();
			msg.m_MethodDeliver[0].m_EventListener = this;
			msg.m_MethodDeliver[0].m_EventId = i;
			card.unitListManager = this;
//			card.manager = sceneManager;
//			card.listManager = this;
            //card.index = i;
//			card.disableOnPress = true;
            card.isSelectUnitMode = true;

            if (CSceneManager.prevSceneIndex == SCENE.UnitMenuScene )
            {
                for (int k = 0; k < MyInfo.Instance.MyDeckMap.Count; k++)
                {
                    for (int j = 0; j < MyInfo.Instance.MyDeckMap[k].SlotMap.Count; j++)
                    {
                        if (MyInfo.Instance.MyDeckMap[k].SlotMap[j].UnitDBID == MyInfo.Instance.MyUnitsList[i].UnitDBID)
                        {
                            if( card.alreadySettingLabel != null )
                                card.alreadySettingLabel.SetActive(true);
                            //card.equipInfoObject.SetActive(true);
                            //card.equipInfoObject.GetComponentInChildren<UILabel>().text = CStringTableManager.Instance.GetItemById(1693).Replace("{index}", (j + 1).ToString());
                            //					card.selectedMark.gameObject.SetActive(true);
                            //					card.collider.enabled = false;
                            msg.enabled = false;
                            msg.m_MethodDeliver[0].m_EventListener = null;
                            card.unitImage.alpha = 0.5f;
                            break;
                        }
                    }
                }
            }
            else
            {
                for (int j = 0; j < MyInfo.Instance.MyDeckMap[MyInfo.Instance.MyCurrentDeck].SlotMap.Count; j++)
                {
                    if (MyInfo.Instance.MyDeckMap[MyInfo.Instance.MyCurrentDeck].SlotMap[j].UnitDBID == MyInfo.Instance.MyUnitsList[i].UnitDBID)
                    {
                        if (card.alreadySettingLabel != null)
                            card.alreadySettingLabel.SetActive(true);
                        //card.equipInfoObject.SetActive(true);
                        //card.equipInfoObject.GetComponentInChildren<UILabel>().text = CStringTableManager.Instance.GetItemById(1693).Replace("{index}", (j + 1).ToString());
                        //					card.selectedMark.gameObject.SetActive(true);
                        //					card.collider.enabled = false;
                        msg.enabled = false;
                        msg.m_MethodDeliver[0].m_EventListener = null;
                        card.unitImage.alpha = 0.5f;
                        break;
                    }
                }

                if (MyInfo.Instance.MyDeckMap[MyInfo.Instance.MyCurrentDeck].GetSameCardCount(MyInfo.Instance.MyUnitsList[i].UnitClassID) >= 2)
                {
                    //if (!card.equipInfoObject.activeSelf)
                    //    card.equipLimitObject.SetActive(true);
                    msg.enabled = false;
                    msg.m_MethodDeliver[0].m_EventListener = null;
                    card.unitImage.alpha = 0.5f;
                }
            }

			cardList.Add(card);
//			cardList[i] = card;
		}
		
		LoadingWindow.window.HideLoading();
		if( currentLoadingCardIndex <= MyInfo.Instance.MyUnitsList.Count )
			GetComponent<UIGrid>().Reposition();
		currentLoadingCardIndex = 10 * loadingPageIndex++;
	}
	
	void SetCardInfo(MyUnitCard card, int unitIndex)
	{
        card.selectedMark.SetActive(false);
        if (card.alreadySettingLabel != null)
            card.alreadySettingLabel.SetActive(false);
        //card.equipLimitObject.SetActive(false);
        //card.equipInfoObject.SetActive(false);
		card.SetCardInfo(unitIndex, MyInfo.Instance.MyUnitsList[unitIndex]);
        if( unitIndex == _selectedCardIndex )
            card.selectedMark.SetActive(true);
        else
            card.selectedMark.SetActive(false);
		LTButtonMessage msg = card.GetComponent<LTButtonMessage>();
		msg.m_MethodDeliver[0].m_EventListener = this;
		msg.m_MethodDeliver[0].m_EventId = unitIndex;
//		card.gameObject.collider.enabled = true;
		msg.enabled = true;
		card.unitImage.alpha = 1.0f;
        if (CSceneManager.prevSceneIndex == SCENE.UnitMenuScene )
        {
            for (int k = 0; k < MyInfo.Instance.MyDeckMap.Count; k++)
            {
                for (int j = 0; j < MyInfo.Instance.MyDeckMap[k].SlotMap.Count; j++)
                {
                    if (MyInfo.Instance.MyDeckMap[k].SlotMap[j].UnitDBID == MyInfo.Instance.MyUnitsList[unitIndex].UnitDBID)
                    {
                        if (card.alreadySettingLabel != null)
                            card.alreadySettingLabel.SetActive(true);
                        //card.equipInfoObject.SetActive(true);
                        //card.equipInfoObject.GetComponentInChildren<UILabel>().text = CStringTableManager.Instance.GetItemById(1693).Replace("{index}", (j + 1).ToString());
                        //					card.selectedMark.gameObject.SetActive(true);
                        //					card.collider.enabled = false;
                        msg.enabled = false;
                        msg.m_MethodDeliver[0].m_EventListener = null;
                        card.unitImage.alpha = 0.5f;
                        break;
                    }
                }
            }
        }
        else
        {
            for (int j = 0; j < MyInfo.Instance.MyDeckMap[MyInfo.Instance.MyCurrentDeck].SlotMap.Count; j++)
            {
                if (MyInfo.Instance.MyDeckMap[MyInfo.Instance.MyCurrentDeck].SlotMap[j].UnitDBID == MyInfo.Instance.MyUnitsList[unitIndex].UnitDBID)
                {
                    if (card.alreadySettingLabel != null)
                        card.alreadySettingLabel.SetActive(true);
                    //card.equipInfoObject.SetActive(true);
                    //card.equipInfoObject.GetComponentInChildren<UILabel>().text = CStringTableManager.Instance.GetItemById(1693).Replace("{index}", (j + 1).ToString());
                    //					card.selectedMark.gameObject.SetActive(true);
                    //					card.collider.enabled = false;
                    msg.m_MethodDeliver[0].m_EventListener = null;
                    //				card.gameObject.collider.enabled = false;
                    msg.enabled = false;
                    card.unitImage.alpha = 0.5f;
                    break;
                }
                else
                {
                    if (card.alreadySettingLabel != null)
                        card.alreadySettingLabel.SetActive(false);
                }
            }
            if (MyInfo.Instance.MyDeckMap[MyInfo.Instance.MyCurrentDeck].GetSameCardCount(MyInfo.Instance.MyUnitsList[unitIndex].UnitClassID) >= 2)
            {
                //if (!card.equipInfoObject.activeSelf)
                //    card.equipLimitObject.SetActive(true);
                msg.enabled = false;
                msg.m_MethodDeliver[0].m_EventListener = null;
                card.unitImage.alpha = 0.5f;
            }
        }
	}

	// Update is called once per frame
	void Update () {		
		int currentCardCount = (int)(panelTrans.localPosition.x / -cardWidth);
//		if( currentLoadingCardIndex >= MyInfo.Instance.MyUnitsList.Count )
//		{
			if( dragDirection < 0 )
			{
				if( currentCardCount - 1 >= 0 && currentCardCount+6 < MyInfo.Instance.MyUnitsList.Count )
				{
                    if (cardList[(currentCardCount - 1) % 7] != null)
                    {
                        cardList[(currentCardCount - 1) % 7].transform.localPosition = new Vector3((cardWidth * 7) + ((currentCardCount - 1) * cardWidth), 0f, 0f);
                        SetCardInfo(cardList[(currentCardCount - 1) % 7], currentCardCount + 6);
                    }
				}
//				if( currentCardCount + 6 < cardList.Count)
//				{
//					cardList[currentCardCount+6].transform.localPosition = new Vector3((currentCardCount-3)*345f, 0f, 0f);
//					cardList[currentCardCount+6].gameObject.SetActive(true);
//				}
//				else
//				{
//					if( currentCardCount+6 < MyInfo.Instance.MyUnitsList.Count )
//					{	
//						MyUnitCard card = LTPrefabManager.InstantiateC(PrefabTypes.Card, Vector3.zero, Quaternion.identity) as MyUnitCard;
//						Transform cardTrans = card.transform;
//						cardTrans.parent = transform;
//						cardTrans.localScale = Vector3.one;
//						cardTrans.localPosition = new Vector3((currentCardCount+6)*345f, 0f, 0f);
//						card.SetCardInfo(currentCardCount+6, MyInfo.Instance.MyUnitsList[currentCardCount+6]); 
//						card.GetComponent<UIButtonMessage>().target = card.gameObject;
//						LTButtonMessage msg = card.GetComponent<LTButtonMessage>();
//						msg.m_MethodDeliver[0].m_EventListener = this;
//						msg.m_MethodDeliver[0].m_EventId = currentCardCount+6;
//						card.index = currentCardCount+6;
//						card.unitListManager = this;
//						cardList.Add(card);
//					}
//				}
			}
			else if( dragDirection > 0 )
			{
				if( currentCardCount - 1 >= 0)
				{
                    if (cardList[(currentCardCount - 1) % 7] != null && cardList[currentCardCount % 7] != null)
                    {
                        cardList[(currentCardCount - 1) % 7].transform.localPosition = new Vector3(cardList[currentCardCount % 7].transform.localPosition.x - cardWidth, 0f, 0f);
                        SetCardInfo(cardList[(currentCardCount - 1) % 7], currentCardCount - 1);
                    }
				}
//				if( currentCardCount + 6 < cardList.Count )
//				{
//					cardList[currentCardCount-3].transform.localPosition = new Vector3((currentCardCount+6)*345f, 0f, 0f);
//					cardList[currentCardCount+6].gameObject.SetActive(false);
//				}
			}
//		}
	}
	
	List<TeamCard> selectedCardList = new List<TeamCard>();
	public void RefreshCardStatus(TeamCard card)
	{
        /*
		DeckInfo deckInfo = MyInfo.Instance.MyDeckMap[MyInfo.Instance.MyCurrentDeck];
		if( selectedCardList.Count == 5 ) return;
		if( selectedCardList.Count == 0 )
		{
//			for(int i=0; i<deckInfo.SlotMap.Count; i++)
//			{
//				if( deckInfo.SlotMap[i].UnitDBID == 0 )
//				{
//					deckInfo.SlotMap[i] = card.unitInfo;
//					break;
//				}
//			}
			deckInfo.SlotMap[DeckEditSceneManager.selectedDeckIndex] = card.unitInfo;
			selectedCardList.Add(card);
			sceneManager.RefreshDeckSlots();
			return;
		}
		
		if( sceneManager.isPartyMode )
		{
			if( card.isSelected )
			{
				for(int i=0; i<deckInfo.SlotMap.Count; i++)
				{
					if( deckInfo.SlotMap[i].UnitDBID == 0 )
					{
						deckInfo.SlotMap[i] = card.unitInfo;
						break;
					}
				}
				selectedCardList.Add(card);
			}
			else
			{
				for(int i=0; i<deckInfo.SlotMap.Count; i++)
				{
					if( deckInfo.SlotMap[i].UnitDBID == card.cardDBId )
					{
						deckInfo.SlotMap[i] = new UnitInfo(0,0,0,0);
						break;
					}
				}
				selectedCardList.Remove(card);
			}
			sceneManager.RefreshDeckSlots();
		}
		else
		{
			if( card.isSelected )
			{
				for(int i=0; i<deckInfo.SlotMap.Count; i++)
				{
					if( deckInfo.SlotMap[i].UnitDBID == 0 )
					{
						deckInfo.SlotMap[i] = card.unitInfo;
						for(int j=i+1; j<deckInfo.SlotMap.Count; j++)
						{
							deckInfo.SlotMap[j] = new UnitInfo(0,0,0,0);
						}
						break;
					}
					else if( deckInfo.SlotMap[i].UnitDBID == selectedCardList[0].cardDBId )
					{
						deckInfo.SlotMap[i] = card.unitInfo;
						break;
					}
				}
				selectedCardList[0].selectedCardEffect.gameObject.SetActive(false);
				selectedCardList[0].alreadySelectedCardMark.gameObject.SetActive(false);
				selectedCardList[0].isSelected = false;
				selectedCardList[0] = card;
			}
			else 
			{
				for(int i=0; i<deckInfo.SlotMap.Count; i++)
				{
					if( deckInfo.SlotMap[i].UnitDBID == card.cardDBId )
					{
						deckInfo.SlotMap[i] = new UnitInfo(0,0,0,0);
						break;
					}
				}
				selectedCardList.Remove(card);
			}
			
			sceneManager.RefreshDeckSlots();
		}
         */
	}
	
	public void RefreshCardStatus(int prevUnitDbId)
	{
		
	}

    int selectedUnitIndex = -1;
	int _selectedCardIndex = -1;
    int _prevSelectedCardIndex = 0;
	public override void OnEvent (int eventID)
	{
        _prevSelectedCardIndex = _selectedCardIndex;
        selectedUnitIndex = eventID;
		if( CSceneManager.m_Scene == SCENE.DeckEditScene )
		{
            for (int i = 0; i < cardList.Count; i++)
            {
                if (cardList[i].index == eventID)
                {
                    _selectedCardIndex = i;
                    break;
                }
            }
            if (_prevSelectedCardIndex != _selectedCardIndex)
            {
                if( _prevSelectedCardIndex > -1 )
                    cardList[_prevSelectedCardIndex].selectedMark.SetActive(false);
                cardList[_selectedCardIndex].selectedMark.SetActive(true);
                SetDetailCardInfo(eventID);
                SetSkillInfo(MyInfo.Instance.MyUnitsList[eventID].UnitClassID);
            }
            else
            {
                cardList[_selectedCardIndex].selectedMark.SetActive(false);
                detailCard.gameObject.SetActive(false);
                skillInfoObject.SetActive(false);
                _selectedCardIndex = -1;
            }

            //LoadingWindow.window.ShowShortLoading();
            //MyInfo.Instance.MyDeckMap[MyInfo.Instance.MyCurrentDeck].SlotMap[DeckEditSceneManager.selectedDeckIndex] = MyInfo.Instance.MyUnitsList[eventID];
            //CSceneManager.manager.GoToDeckEditScene();
		}
		else if( CSceneManager.prevSceneIndex == SCENE.UnitLevelupScene )
		{
			MyInfo.Instance.LastSelectedUnitDBID = MyInfo.Instance.MyUnitsList[eventID].UnitDBID;
			MyInfo.Instance.LastSelectedUnitID = MyInfo.Instance.MyUnitsList[eventID].UnitClassID;
			CSceneManager.manager.GoToUnitLevelUpScene();
		}
		else if( CSceneManager.prevSceneIndex == SCENE.UnitMenuScene  )
		{
			string[] param = new string[1];
			CUnitData unitData = CUnitDataManager.Instance.GetUnitData(MyInfo.Instance.MyUnitsList[eventID].UnitClassID);
			int baseCost = CGSettingDataManager.Instance.GetSellUnitCost(unitData.grade);
			int additionalCost = unitData.price_mod;
			param[0] = (baseCost + additionalCost).ToString();
			_selectedCardIndex = eventID;
			MessagePopup.window.ShowPopup(MESSAGEPOPUPTYPE.SellUnitWarning, param, MessagePopupCallback); 
			
		}
	}

    void ClickedFinishButton()
    {
        if (_selectedCardIndex > -1)
        {
            cardList[_selectedCardIndex].selectedMark.SetActive(false);
            MyInfo.Instance.MyDeckMap[MyInfo.Instance.MyCurrentDeck].SlotMap[DeckEditSceneManager.selectedDeckIndex] = MyInfo.Instance.MyUnitsList[selectedUnitIndex];
            _selectedCardIndex = -1;
        }
        detailCard.gameObject.SetActive(false);
        skillInfoObject.SetActive(false);
        Debug.LogError("selectedDeckIndex - " + DeckEditSceneManager.selectedDeckIndex);
            
        foreach (MyUnitCard card in cardList)
        {
            card.transform.localPosition = new Vector3(1000f, 1000f, 0f);
            Destroy(card.gameObject);
        }
        cardList.Clear();
        Vector2 range = transform.parent.GetComponent<UIPanel>().clipOffset;
        range.x = 0f;
        transform.parent.GetComponent<UIPanel>().clipOffset = range;
        //transform.parent.GetComponent<UIScrollView>().ResetPosition();
        Vector3 pos = transform.parent.localPosition;
        pos.x = 200f;
        transform.parent.localPosition = pos;
        dragDirection = 0;
        currentLoadingCardIndex = 0;
        sceneManager.OnClickedCardSelectFinishButton();
    }

    public void OnClickedBackButton()
    {
        detailCard.gameObject.SetActive(false);
        skillInfoObject.SetActive(false);
        if(_selectedCardIndex > -1 )
            cardList[_selectedCardIndex].selectedMark.SetActive(false);
        _selectedCardIndex = -1;
        foreach (MyUnitCard card in cardList)
        {
            card.transform.localPosition = new Vector3(1000f, 1000f, 0f);
            Destroy(card.gameObject);
        }
        cardList.Clear();
        Vector2 range = transform.parent.GetComponent<UIPanel>().clipOffset;
        range.x = 0f;
        transform.parent.GetComponent<UIPanel>().clipOffset = range;
        //transform.parent.GetComponent<UIScrollView>().ResetPosition();
        Vector3 pos = transform.parent.localPosition;
        pos.x = 200f;
        transform.parent.localPosition = pos;
        dragDirection = 0;
        currentLoadingCardIndex = 0;
        sceneManager.OnClickedCardSelectFinishButton();
    }

	public void SetDetailCardInfo(UnitInfo unitInfo)
	{
		detailCard.SetCardInfo(0, unitInfo);
		detailCard.gameObject.SetActive(true);
	}

    public void SetDetailCardInfo(int index)
    {
        if (_prevSelectedCardIndex != index)
        {
            detailCard.SetCardInfo(0, MyInfo.Instance.MyUnitsList[index]);
            detailCard.gameObject.SetActive(true);
        }
        else
        {
            detailCard.gameObject.SetActive(false);
        }
    }

    public void SetSkillInfo(int unitClassId)
    {
        CUnitData unitData = CUnitDataManager.Instance.GetUnitData(unitClassId);
        if (unitData == null) return;

        string[] splitSkillString = new string[0];
        if (!string.IsNullOrEmpty(unitData.passive_skill))
            splitSkillString = unitData.passive_skill.Split(';');

        if (splitSkillString.Length != 0)
        {
            CSkillData skillData = CSkillDataManager.Instance.FindSkillData(splitSkillString[0]);
            if (skillData != null)
            {
                skillName.text = CStringTableManager.Instance.GetItemByName(skillData.name_string);
                skillDesc.text = CStringTableManager.Instance.GetItemByName(skillData.desc_string);
                skillMP.text = "MP " + skillData.cost;
                skillInfoObject.SetActive(true);
            }
        }
    }

	public void EmptySelectedCardList()
	{
		foreach(TeamCard card in selectedCardList)
		{
			card.selectedCardEffect.gameObject.SetActive(false);
			card.alreadySelectedCardMark.gameObject.SetActive(false);
			DeckInfo deckInfo = MyInfo.Instance.MyDeckMap[MyInfo.Instance.MyCurrentDeck];
			for(int i=0; i<deckInfo.SlotMap.Count; i++)
			{
				if( deckInfo.SlotMap[i].UnitDBID == card.cardDBId )
				{
					deckInfo.SlotMap[i] = new UnitInfo(0,0,0,0);
					break;
				}
			}
		}
		
		selectedCardList.Clear();
        //sceneManager.RefreshDeckSlots();
	}
	
	int dragDirection = 0;
	public void Drag(Vector2 delta)
	{
		dragDirection = delta.x < 0 ? -1 : 1;
	}

	public void RestCallback(Hashtable returnData)
	{
		MyInfo.Instance.MyUnitsList.RemoveAt(_selectedCardIndex);
		CSceneManager.manager.GoToUnitMenuScene();
	}

	public void MessagePopupCallback(MESSAGEPOPUPTYPE type, bool isYes)
	{
		if( isYes )
		{
			LoadingWindow.window.ShowShortLoading();
			RestAPI.singleton.SellUnitCard(RestCallback, MyInfo.Instance.MyUnitsList[_selectedCardIndex].UnitDBID);
		}
	}
}
